import axios from 'axios'
// import { Message } from 'element-ui'
// import { Toast } from 'vant'
// import store from '@/store'
// import { getToken } from '@/utils/auth'
import qs from 'qs'

// const baseURL =  process.env.NODE_ENV === 'production' ? 'http://xpw.yanyouxue.cn' : 'api'
const baseURL = 'https://warranty.xpel.com.cn';

const service = axios.create({
  baseURL: baseURL, // url = base url + request url
  withCredentials: false, // send cookies when cross-domain requests
  timeout: 5000 // request timeout
})

// request interceptor
service.interceptors.request.use(
  config => {
    config.headers['content-type'] = 'application/x-www-form-urlencoded'
    const method = config.method.toLocaleLowerCase()
    if (method === 'post') {
      config.data = qs.stringify(config.data)
    }
    return config
  },
  error => {
    console.log(error)
    return Promise.reject(error)
  }
)

// response interceptor
service.interceptors.response.use(
  response => {
    return response.data
  },
  error => {
    console.log('err' + error) // for debug
    return Promise.reject(error)
  }
)

export default service
